#ifndef _WORLDSOCKET_H
#define _WORLDSOCKET_H

class Session;

class DataBuffer
{
	Mutex m_access;
	vector<ui8> _data;
public:
	void Push(ui8* src, ui32 len);
	void Pop(ui8* dest, ui32 len);
	void BlockAccess();
	void AllowAccess();
	void Clear() { _data.clear(); }
	ui32 GetWaitingBytes() { return _data.size(); }
	ui8* Contents() { return (&_data.front()); }
	DataBuffer();
};

class DLL_EXPORT WorldSocket : public CThread, public Single<WorldSocket>
{
	fd_set fset;
	SOCKET m_listensocket;
	set<Session*> m_sessions;
	Mutex m_sessionlock;
	ui32 m_request;
public:
	WorldSocket() : m_request(0)
	{
	}
	void Loop();
	ui32 GetNewRequest() { return m_request++; }
	Session* GetSessionByRequest(ui32 id);
};

#define sWorldSocket WorldSocket::getSingle()

#endif